package com.lzy.mall.common.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lzy.mall.common.constant.Constant;
import org.beetl.sql.core.engine.PageQuery;

import java.util.Map;

/**
 * @author lzy
 * @date 2021/8/27 17:04
 */
public class PageParaUtils {
    public static PageQuery pagePara(Map<String,Object> params){
        if (CollUtil.isEmpty(params)){
            return new PageQuery();
        }

        PageQuery pageQuery = new PageQuery();
        if (ObjectUtil.isNotNull(params.get(Constant.PAGE))){
            String pageNumber = (String) params.get(Constant.PAGE);
            pageQuery.setPageNumber(Long.parseLong(pageNumber));
        }
        if (ObjectUtil.isNotNull(params.get(Constant.LIMIT))){
            String pageSize = (String) params.get(Constant.LIMIT);
            pageQuery.setPageSize(Long.parseLong(pageSize));
        }
        if (StrUtil.isNotBlank((String) params.get("key"))){
            String key = (String) params.get("key");
            pageQuery.setPara("key",key);
        }
        return pageQuery;
    }
}
